const Router = require('koa-router')
const router = new Router()
router.prefix('/api/user')

const { //控制器
  findList, create, update,
  findById, login, checkUserExist,
  uploadAvatar, delete: del, checkOwner,
  md5Password
} = require('../controllers/user')

const { //中间件
  auth, checkUserAuthorization
} = require('../middleware/index')

router.get('/', findList) //获取用户列表

router.get('/:id', checkUserExist, findById) //获取指定用户详情

router.put('/:id/avatar', auth, checkOwner, checkUserExist, uploadAvatar) //上传用户头像

router.post('/login', md5Password, login) // 登录

router.post('/', md5Password, create) //新建用户

router.patch('/:id', auth, checkOwner, checkUserExist, update) //更新用户

router.delete('/:id', auth, checkUserAuthorization, checkUserExist, del) //删除用户

module.exports = router
